<template>
  <div class="live-name-audit">
    <div class="top flex-left">
      <div class="category-select flex-left">
        <label>状态</label>
        <el-select v-model="searchForm.status" placeholder="请选择" size="medium" @change="search">
          <el-option v-for="item in list" :key="item.value" :label="item.key" :value="item.value"></el-option>
        </el-select>
      </div>
    </div>
    <!-- 数据表 -->
    <div class="data-table">
      <el-table
        size="medium"
        v-loading="loading"
        element-loading-text="拼命加载中..."
        element-loading-spinner="el-icon-loading"
        element-loading-background="rgba(211, 215, 212, 0.5)"
        :data="tableData"
        stripe
        header-cell-class-name="headerStyle"
        style="width: 100%"
      >
        <el-table-column align="center" label="修改前标题" prop="current_title"></el-table-column>
        <el-table-column align="center" label="修改后标题" prop="new_title"></el-table-column>
        <el-table-column align="center" prop="apply_id" label="申请人"></el-table-column>
        <el-table-column align="center" prop="create_time" label="时间"></el-table-column>
        <el-table-column align="center" label="操作" width="120">
          <template slot-scope="item">
            <div v-if="item.row.status==0">
              <el-button type="text" @click="audit(item.row.id,1)">通过</el-button>
              <el-button type="text" style="color:red" @click="audit(item.row.id,2)">拒绝</el-button>
            </div>
            <span v-else>{{item.row.status==1?"已通过":"已拒绝"}}</span>
          </template>
        </el-table-column>
      </el-table>
      <!-- 分页 -->
      <pages :pages="searchForm" :total="total" @pageChange="pageChange" layout="prev, pager, next"></pages>
      <transition name="fade">
        <img-view :img="imgUrl" v-if="showImg" @cancel="showImg=false"></img-view>
      </transition>
    </div>
  </div>
</template>

<script>
import Pages from "@/components/PageBox.vue";
import ImgView from "@/components/Explorer/ImgView.vue";
import { nameList, nameAudit } from "./live.service";
export default {
  components: {
    Pages,
    ImgView
  },
  data() {
    return {
      loading: false,
      tableData: [],
      list: [
        { key: "待审核", value: 0 },
        { key: "已通过", value: 1 },
        { key: "已拒绝", value: 2 }
      ],
      total: 0,
      searchForm: {
        page: 1,
        size: 10,
        status: 0,
        platform_id: ""
      },
      imgUrl: "",
      showImg: false
    };
  },
  mounted() {
    this.search();
  },
  methods: {
    async search() {
      this.loading = true;
      const res = await nameList(this.searchForm);
      this.tableData = res.data.items || [];
      this.total = res.data.total || 0;
      this.loading = false;
    },
    async audit(id, status) {
      const res = await nameAudit({ id, status });
      if (res.code == 0) {
        this.search();
        this.$notify({
          title: "提示",
          message: "审核成功",
          type: "success"
        });
      }
    },
    viewImg(url) {
      this.imgUrl = url;
      this.showImg = true;
    },
    pageChange(val) {
      this.searchForm.page = val;
      this.search(this.searchForm);
    }
  }
};
</script>

<style lang="scss">
.live-name-audit {
  position: relative;
  min-height: calc(100vh - 100px);
  .top {
    .input-with-select {
      width: 341px;
      .el-input-group__append {
        background-color: #66b1ff;
        color: #fff;
      }
    }
    .category-select,
    .wallet-select {
      width: 230px;
      margin-right: 30px;
      color: #606266;
      label {
        width: 60px;
        flex-shrink: 1;
      }
    }
  }
  .data-table {
    position: relative;
    padding-bottom: 20px;
    background: #fff;
    border-radius: 5px;
    margin-top: 20px;
    box-shadow: rgba(0, 0, 0, 0.1) 0 0 15px;
    .scaleImg {
      max-width: 120px;
      max-height: 23px;
      cursor: pointer;
    }
    .link {
      color: #409eff !important;
    }
  }
  .fade-enter-active,
  .fade-leave-active {
    transition: opacity 0.3s;
  }
  .fade-enter, .fade-leave-to /* .fade-leave-active below version 2.1.8 */ {
    opacity: 0;
  }
}
</style>